;(function($){
	//获取开台消费项目
	$.fn.get_item_html = function(opts){
		var el = this;
		var opt = {
			ds : [],
			dataBack : function(){},
			closeBack : function(){},
		}
		var param = $.extend(opt,opts);
		var app = new App(el,param);
	}
	
	var App = function(el,param){
		this.el = el;
		this.param = param;
		this.initHtml();
		this.initItemHtml();
		this.bindEvent();
	}
	
	App.prototype = {
		bindEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			//选择押金
			el.find("#depositContainer").find("label").unbind("click").click(function(){
				var value = $(this).find("input[name=deposit_option]").val();
				var dcode = el.find("#deposit").attr("data-dcode");
				if(dcode){
					el.find("#deposit").val(value);
					if(value){
						$(this).attr("data-text",el.find("#deposit").data("type")+":"+value);
					}else{
						$(this).attr("data-text","");
					}
				}else{
					$(this).attr("data-text","");
					setTimeout(function(){
						el.find("#depositContainer").find(".active").removeClass("active");
					},0)
				}
			});
			
			//选择押金类型
			el.find("#depositcodeContainer").find("label").unbind("click").click(function(){
				var value = $(this).data("value");
				var dcode = $(this).data("dcode");
				if(dcode){
					el.find("#deposit").removeAttr("readonly");
				}else{
					el.find("#deposit").attr("readonly","readonly").val("");
					el.find("#depositContainer").find(".active").removeClass("active");
				}
				el.find("#deposit").attr("data-type",value).attr("data-dcode",dcode);
				el.find("#deposit").data("type",value).data("dcode",dcode);
			});
			
			//押金输入按钮
			el.find("#deposit_help").unbind("click").click(function(){
				//计算器
				var status = false;
				if(!$.isFunction($().wechatAlipayPay)){
					$.ajaxSetup({ async: false, cache: false });
		            $.getScript("js/openSpa/jquery.plugin.digitalCalculator.js");
		            $.ajaxSetup({ async: true });
				}
				el.find("#mykeyboard").digitalCalculator({
					number:el.find("#pay").val()?el.find("#pay").val():1,//数量
					status:status?status:false,
					title:param.title?param.title:"",
					//初始化数据返回回调
					dataBack:function(number){
						el.find("#mykeyboard").hide();
 						el.find("#pay").val(number);
 						if(number > parseInt(param.price)&&param.totalPrice!=number){
 							el.find("#change").val(checkTwoPoint(number * 1 - param.price * 1));
 						}
					},
					returnBack :function(){
						el.find("#mykeyboard").hide();
					}
				});
			})
			
			//隐藏项目按钮
			el.find(".open-table-option-close").find("button").unbind("click").click(function(){
				var hideid = $(this).data("hideid");
				el.find("#"+hideid).toggle(function(){
					el.find("#"+hideid).find(".shoupaiDefault").trigger("click");
					param.setSizeBack();
				});
			})
		},
		initHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			var html = 	'<style>'+
							'.widget-main.open-table-option{'+
								'padding: 5px;'+
								'display : flex;'+
							'}'+
							'.open-table-option .open-table-option-name{'+
							    'width: 70px;'+
							    'text-align: right;'+
							    'padding: 3px;'+
							    'margin-right: 10px;'+
							    'display: inline-block;'+
							    'vertical-align: top;'+
							    'font-size: 16px;'+
							    'padding-top: 6px;'+
							'}'+
							'.open-table-option .open-table-option-close{'+
								'width: 50px;'+
							'}'+
							'.open-table-option-box{'+
								'width: calc(100% - 80px);'+
							    'display: inline-block;'+
							'}'+
							'.btn.btn-yellow, .btn.btn-yellow:focus {'+
							    'background-color: #ededed !important;'+
							    'border-color: #ededed !important;'+
							'}'+
							'.btn-yellow.active {'+
								'color: #fff !important;'+
								'background-color: #2f7bba !important;'+
							  	'border-color: #27689d !important;'+
							'}'+
							'.btn-yellow.btn-yellow1.active {'+
								'color: #996633 !important;'+
							  	'background-color: #fee188 !important;'+
						   	 	'border-color: #fee188 !important;'+
							'}'+
							'label.btn{'+
							    'height: 42px !important;'+
							    'font-size: 16px !important;'+
							    'vertical-align: middle !important;'+
							    'text-align: center;'+
							    'padding-top: 7px;'+
							'}'+
							'.input-group .form-control.inputEntry {'+
							    'position: relative;'+
							    'z-index: 2;'+
							    'float: left;'+
							    'width: 100%;'+
							    'margin-bottom: 0;'+
							    'height: 42px;'+
							    'font-size: 16px;'+
							'}'+
							'.btn-sm.btn-shoupai {'+
							    'border-width: 4px;'+
							    'font-size: 13px;'+
							    'padding: 4px 9px;'+
							    'line-height: 1.39;'+
							    'height: 42px;'+
							'}'+
							'.consumeBox{'+
								'margin: 0px 2px 2px 0px !important;'+ 
							'}'+
							'.timeBox{'+
								'margin: 0px 2px 2px 0px !important;'+ 
							'}'+
							'.depositBox{'+
								'margin: 0px 2px 2px 0px !important;'+ 
							'}'+
						'</style>'+
						'<div class="mykb-box" id="mykeyboard"></div>'+
						'<div id="operBody_ktxf" class="widget-box">'+
							'<div class="widget-header hide">'+
								'<h5 class="widget-title">'+
									$.i18n.propJsp("消费")+
								'</h5>'+
							'</div>'+
							'<div class="widget-body">'+
								'<div class="widget-main open-table-option">'+
									'<div class="open-table-option-name">'+
										'<i data-icon="ktxf" class="ace-icon fa fa-shopping-cart icon-ktxf"></i>'+
										$.i18n.propJsp("消费")+
									'</div>'+
									'<div class="clearfix open-table-option-box">'+
										'<span id="ktxfContainer" data-toggle="buttons" class="btn-group">'+// style="zoom:94%;"
										
			    						'</span>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>'+
						'<div id="operBody_ktjs" class="widget-box">'+
							'<div class="widget-header hide">'+
								'<h5 class="widget-title">'+
									$.i18n.propJsp("计时")+
								'</h5>'+
							'</div>'+
							'<div class="widget-body">'+
								'<div class="widget-main open-table-option">'+
									'<div class="open-table-option-name">'+
										'<i data-icon="ktjs" class="ace-icon fa fa-bell icon-ktjs"></i>'+
										$.i18n.propJsp("计时")+
									'</div>'+
									'<div class="clearfix open-table-option-box">'+
										'<span id="ktjsContainer" data-toggle="buttons" class="btn-group">'+// style="zoom:94%;"
											
			    						'</span>'+
									'</div>'+
									'<div class="open-table-option-close">'+
										'<button type="button" data-hideId="operBody_ktjs" class="close" data-dismiss="alert">'+
											'<i class="ace-icon fa fa-times"></i>'+
										'</button>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>'+
						'<div id="operBody_deposit" class="widget-box">'+
							'<div class="widget-header hide">'+
								'<h5 class="widget-title">'+
									$.i18n.propJsp("押金")+
								'</h5>'+
							'</div>'+
							'<div class="widget-body">'+
								'<div class="widget-main open-table-option">'+
									'<div class="open-table-option-name">'+
//										$.i18n.propJsp("押金类型")+
									'</div>'+
									'<div class="clearfix open-table-option-box">'+
										'<span id="depositcodeContainer" data-toggle="buttons" class="btn-group">'+// style="zoom:91%;"
											
			    						'</span>'+
									'</div>'+
									'<div class="open-table-option-close">'+
										'<button type="button" data-hideId="operBody_deposit" class="close" data-dismiss="alert">'+
											'<i class="ace-icon fa fa-times"></i>'+
										'</button>'+
									'</div>'+	
								'</div>'+
								'<div class="widget-main open-table-option">'+
									
									'<div class="open-table-option-name">'+
										'<i data-icon="deposit" class="ace-icon fa fa-rmb icon-deposit"></i>'+
										$.i18n.propJsp("押金")+
									'</div>'+
									'<div class="clearfix open-table-option-box">'+
										'<div class="input-group" style="width:138px;float:left;">'+//180px
											'<input type="text" style="margin-left: -3px;" class="form-control search-query inputEntry" data-dcode="" data-type="" id="deposit" name="deposit" readonly/>'+
											'<span class="input-group-btn hide">'+
												'<button type="button" data-name="sl" class="btn btn-primary btn-sm btn-shoupai" id="deposit_help">'+
													'<span class="ace-icon fa fa-keyboard-o icon-on-right bigger-110"></span>'+
												'</button>'+
											'</span>'+
										'</div>'+
										'<span id="depositContainer" data-toggle="buttons" class="btn-group" style="margin-left:20px;">'+//zoom:91%;
											
			    						'</span>'+
									'</div>'+
								'</div>'+
								
								
							'</div>'+
						'</div>'+
						'<div id="operBody_room" class="widget-box">'+
							'<div class="widget-header hide">'+
								'<h5 class="widget-title">'+
									$.i18n.propJsp("客房")+
								'</h5>'+
							'</div>'+
							'<div class="widget-body">'+
								'<div class="widget-main open-table-option">'+
									
									'<div class="open-table-option-name">'+$.i18n.propJsp("房号")+'</div>'+
									'<div class="clearfix open-table-option-box">'+
										'<div class="input-group" style="width:180px;float:left;">'+
											'<input type="text" class="form-control search-query inputEntry" id="room" name="room">'+
											'<span class="input-group-btn">'+
												'<button type="button" data-name="sl" class="btn btn-primary btn-sm btn-shoupai" id="room_help">'+
													'<span class="ace-icon fa fa-home icon-on-right bigger-110"></span>'+
												'</button>'+
											'</span>'+
										'</div>'+
									'</div>'+
									'<div class="open-table-option-close">'+
										'<button type="button" data-hideId="operBody_room" class="close" data-dismiss="alert">'+
											'<i class="ace-icon fa fa-times"></i>'+
										'</button>'+
									'</div>'+	
								'</div>'+
							'</div>'+
						'</div>'+
						'<div id="" class="widget-box">'+
							'<div id="" class="widget-box transparent" style="margin:0px;">'+
								'<div class="widget-body">'+
									'<div class="widget-main open-table-option" style="">'+
										'<div class="open-table-option-name" style="">'+$.i18n.propJsp("手牌")+'</div>'+
										'<div class="clearfix open-table-option-box">'+
											'<div class="input-group" style="width:180px;float:left;">'+
												'<input type="text" class="form-control search-query inputEntry" id="th" name="th" style="text-transform:uppercase;margin-left:-3px;">'+
												'<span class="input-group-btn">'+
													'<button type="button" data-name="sl" class="btn btn-primary btn-sm btn-shoupai" id="th_help">'+
														'<span class="ace-icon fa fa-credit-card icon-on-right bigger-110"></span>'+
													'</button>'+
												'</span>'+
											'</div>'+
											'<span id="" data-toggle="buttons" class="btn-group" style="margin-left:20px;">'+//zoom:91%;
												'<label class="btn btn-primary" style="margin-right:5px;">'+
													'<span>'+$.i18n.propJsp("添加")+'</span>'+
												'</label>'+
												'<label class="btn btn-primary" style="margin-right:5px;">'+
													'<span>'+$.i18n.propJsp("刷卡")+'</span>'+
												'</label>'+
				    						'</span>'+
											'<label class="pull-right" id="rbradio" style="line-height: 27px;margin:0">'+
												'<i class="smaller-90" aria-hidden="true" style="float: left;margin-top: 2px; font-style:normal">可用手牌:</i>'+
												'<input id="showCard" type="checkbox" class="ace ace-switch ace-switch-6" style="margin-top: 8px;" checked="checked">'+
												'<span class="lbl middle" style="margin-top: 2px;"></span>'+
											'</label>'+
										'</div>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>';
			el.html(html);
		},
		initItemHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			//初始开台消费
			var ktxf_html = '<label data-value="" data-xf_dj="" data-name="ktxf" data-text="" data-sort="1" class="shoupaiDefault consumeBox btn btn-yellow active">'+
								'<span class="ui-button-text">'+
									'<input type="radio" name="ktxf_option" value="">'+
									'<span>'+$.i18n.propJsp("默认")+'</span>'+
								'</span>'+
							'</label>';
			$(param.ktxf).each(function(k,v){
				var active = "";
				if(k==0){
					active = "active";
				}
				ktxf_html +='<label data-value="'+v.bh+'" data-xf_dj="'+v.dj+'" data-name="ktxf" data-sort="1" data-text="'+v.mc+'&nbsp;'+(v.dj||"0.00")+'" class="consumeBox btn btn-yellow btn-yellow1 ">'+//'+active+'
								'<span class="ui-button-text">'+
									'<input type="radio" name="ktxf_option" value="'+v.bh+'">'+
									'<span>'+v.mc+'</span>'+
								'</span>'+
							'</label>';
			});
			el.find("#ktxfContainer").html(ktxf_html);
			
			//初始开台计时
			var ktjs_html = '<label data-value="" data-name="ktjs" data-text="" data-sort="2" class="shoupaiDefault timeBox btn btn-yellow active">'+
								'<span class="ui-button-text">'+
									'<input type="radio" name="ktjs_option" value="">'+
									'<span>'+$.i18n.propJsp("默认")+'</span>'+
								'</span>'+
							'</label>';
			$(param.ktjs).each(function(k,v){
				var active = "";
				if(k==0){
					active = "active";
				}
				ktjs_html +='<label data-value="'+v.bh+'" data-name="ktjs" data-sort="2" data-text="'+v.mc+'" class="timeBox btn btn-yellow btn-yellow1">'+//'+active+'
								'<span class="ui-button-text">'+
									'<input type="radio" name="ktjs_option" value="'+v.bh+'">'+
									'<span>'+v.mc+'</span>'+
								'</span>'+
							'</label>';
			});
			el.find("#ktjsContainer").html(ktjs_html);
			
			
			//初始押金类型
			var depositcode_html = "";
			var depositcode_html = '<label data-value="" data-dcode="" data-name="depositcode" data-text="" class="shoupaiDefault depositBox btn btn-yellow active">'+
										'<span class="ui-button-text">'+
											'<input type="radio" name="ktjs_option" value="">'+
											'<span>'+$.i18n.propJsp("无押金")+'</span>'+
										'</span>'+
									'</label>';
			$(param.depositcode).each(function(k,v){
				var active = "";
				if(k==0){
					active = "active";
				}
				depositcode_html +='<label data-name="depositcode" data-dcode="'+v.dcode+'" data-value="'+v.text+'" class="depositBox btn btn-yellow btn-yellow1">'+//'+active+'
								'<span class="ui-button-text">'+
									'<input type="radio" name="depositcode_option" value="'+v.dcode+'">'+
									'<span>'+v.text+'</span>'+
								'</span>'+
							'</label>';
			});
			el.find("#depositcodeContainer").html(depositcode_html);
			//初始押金
			var deposit_html = "";
			$(param.deposit).each(function(k,v){
				var active = "";
				if(k==0){
					active = "active";
				}
				deposit_html += '<label data-value="'+v+'" data-name="deposit" data-sort="3" class="depositBox btn btn-yellow btn-yellow1">'+//'+active+'
									'<span class="ui-button-text">'+
										'<input type="radio" name="deposit_option" value="'+v+'">'+
										'<span>'+v+'</span>'+
									'</span>'+
								'</label>';
			})
			el.find("#depositContainer").html(deposit_html);
		},
	}
	
	function getContextPath(){
		var pathName = document.location.pathname;
		var index = pathName.substr(1).indexOf("/");
		var path = pathName.substr(0, index + 1);
		return path;
	}
})(jQuery);